package com.cn.ryc.mapper;

import com.cn.ryc.model.Alarm;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface AlarmMapper {


    // 根据id查询警报信息
    @Select("SELECT * FROM alarms WHERE id = #{id}")
    Alarm findById(@Param("id") Long id);

    // 更新警报信息的状态
    @Update("UPDATE alarms SET processed = #{processed}, process_time = #{processTime} WHERE id = #{id}")
    void updateAlarmStatus(@Param("id") Long id, 
                           @Param("processed") Boolean processed, 
                           @Param("processTime") LocalDateTime processTime);

    // 插入新的警报信息
    @Insert("INSERT INTO alarms (time, type, level, video_url, description, processed, created_at) " +
            "VALUES (#{time}, #{type}, #{level},  #{videoUrl}, #{description}, #{processed}, #{createdAt})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertAlarm(Alarm alarm);

    @Select("SELECT * FROM alarms ORDER BY time DESC")
    List<Alarm> findAllAlarms();
} 